package com.quickcode.example.threads;

/**
 * 线程中断后，如果不人为的将其逻辑结束，其还会正常运行
 * Created by 张波 on 2020/5/2.
 */
public class ThreadInterupted {


    public static class TestRunable implements Runnable {

        @Override
        public void run() {
            System.out.println("线程开始执行");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println("线程中断");
                Thread.interrupted();
            }
            System.out.println("中断后还在执行");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println("线程中断2");
            }
            System.out.println("线程结束咯");
        }
    }


    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new TestRunable());

        t.start();
        Thread.sleep(1000);
        t.interrupt();
        Thread.sleep(2000);
        System.out.println("主线程结束");
    }

}
